package org.lds.hotkey.console.business.currhotkey.converter;

import org.lds.hotkey.console.business.currhotkey.entity.CurrHotKey;
import org.lds.hotkey.console.business.currhotkey.model.request.CurrHotKeyBaseUpdateRequest;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;


@Component
public class CurrHotKeyBaseUpdateRequestToEntityConverter implements Converter<CurrHotKeyBaseUpdateRequest, CurrHotKey> {

    @Override
    public CurrHotKey convert(CurrHotKeyBaseUpdateRequest source) {
        return CurrHotKey.builder()
            .id(source.getId())
            .expireTime(source.getDuration() * 1000 + System.currentTimeMillis())
            .createTime(LocalDateTime.now())
            .build();
    }

}


